<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">客户列表</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="客户名称" prop="searchValue">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="请输入客户名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="list-search btn-success" color="#5ED4D4">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="list-search">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            class="btn-success"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="userAdd()"
            v-hasPermi="['system:customerInformation:insert']"
          >新建</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="userList" @row-click="handleView" :default-sort="{prop: 'date', order: 'descending'}" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="编号" align="center" prop="code" :show-overflow-tooltip="true" width="200" sortable />
        <el-table-column label="名称" align="center" prop="name" :show-overflow-tooltip="true" width="200" />
        <!-- <el-table-column label="简称" align="center" prop="abbreviation"  :show-overflow-tooltip="true" /> -->
        <!-- <el-table-column label="销售区域" align="center" prop="salesAreaName" :show-overflow-tooltip="true" /> -->
        <el-table-column label="币种" align="center" prop="currency" :show-overflow-tooltip="true" />
        <el-table-column label="联系人" align="center" prop="contact" :show-overflow-tooltip="true" />
        <!-- <el-table-column label="付款条件" align="center" prop="paymentTerms" :show-overflow-tooltip="true" /> -->
        <el-table-column label="创建者" align="center" prop="createBy" />
        <el-table-column value-format="yyyy-MM-dd" label="创建日期" align="center" prop="createTime" width="180px" />
        <el-table-column label="审核状态" align="center" prop="approvalStatus">
          <template slot-scope="scope">
            <div v-if="scope.row.approvalStatus == 0" style="color:#13C2C2">草稿</div>
            <div v-if="scope.row.approvalStatus == 1" style="color:#13C2C2">待审核</div>
            <div v-if="scope.row.approvalStatus == 2" style="color:#52C41A">已审核</div>
            <div v-if="scope.row.approvalStatus == 3" style="color:#fd562c">拒绝</div>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" style="color:#13C2C2">禁用</div>
            <div v-if="scope.row.status == 1" style="color:#52C41A">正常</div>
          </template>
        </el-table-column>
        <el-table-column label="最后更新" align="center" prop="updateBy" />
        <el-table-column value-format="yyyy-MM-dd" label="更新日期" align="center" prop="updateTime" width="180px" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click.native.stop="handleDelete(scope.row)"
              v-hasPermi="['system:customerInformation:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listUser, listUserDelete } from "@/api/system/basicdata/basicdata"

export default {
  name: "user",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 生产列表数据
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // approvalStatus: 2,
        // status: 1,
        searchValue:undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      listUser(this.addDateRange(this.queryParams)).then(res => {
          this.userList = res.rows
          this.total = res.total
          this.loading = false
      })
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 新建
    userAdd(){
      this.$router.push({path:"/customer/user/add"})
    },
    // 查看详情
    handleView(row) {
      this.$router.push({path:"/customer/user/detail", query:{id: row.id, type: 'user'}})
    },
    // 删除
    handleDelete(row){
      this.$modal.confirm('是否确认删除？').then(() => {
        listUserDelete(row.id).then(() => {
          this.getList()
          this.$modal.msgSuccess("删除成功")
        })
      }).catch(() => {})
    },
  }
}
</script>